<template>
    <ClientOnly>
        <Teleport to="body">
            <div v-show="visible" class="chat-container">
                <div class="close-icon" @click="emits('close')">
                    <Icon name="el-icon-Close" :size="18" />
                </div>
                <iframe
                    width="100%"
                    height="100%"
                    border="none"
                    :src="link"
                ></iframe>
            </div>
        </Teleport>
    </ClientOnly>
</template>

<script lang="ts" setup>
import useAppStore from '@/stores/app'

const emits = defineEmits(['close'])
const props = defineProps({
    show: {
        type: Boolean,
        default: false
    }
})

const appStore = useAppStore()

const visible = ref<boolean>(false)
const link = computed(() => appStore.getWebsiteConfig.customer_link)

watch(
    () => props.show,
    (val: boolean) => {
        visible.value = val
    }, { immediate: true }
)
</script>

<style lang="scss" scoped>
.chat-container {
    position: fixed;
    right: 12px;
    bottom: 12px;
    z-index: 999999;
    display: block;
    width: 50%;
    max-width: 420px;
    height: 62vh;
    max-height: 667px;
    overflow: hidden;
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: rgb(0 0 0 / 16%) 0 8px 32px 0;
    .close-icon {
        position: absolute;
        top: 35px;
        right: 16px;
        display: flex;
        color: #333333;
        cursor: pointer;
        transform: translateY(-50%);
    }
}
</style>
